/*
 * @Description: 单元格自定义组件
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-05-18 11:52:35
 * @LastEditTime: 2021-05-18 18:28:22
 */
import { h, defineComponent } from 'vue'
import { Popover } from 'ant-design-vue'
import { componentMap } from './componentMap'
import { ComponentProps } from './type'

export const CellComponent = (
	{
		component = 'Input',
		rule = true,
		ruleMessage,
		popoverVisible,
	}: ComponentProps,
	{ attrs }: any
) => {
	const Comp = componentMap.get(component) as typeof defineComponent

	const DefaultComp = h(Comp, attrs)

	if (!rule) {
		return DefaultComp
	}
	return h(
		Popover,
		{ overlayClassName: 'edit-rule-popover', visible: !!popoverVisible },
		{
			default: () => DefaultComp,
			content: () => ruleMessage,
		}
	)
}
